﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Library;
using System.Xml;
using Microsoft.Reporting.WinForms;

namespace QLKH.View.report
{
    public partial class reportTuGiaDung : Form
    {
        public reportTuGiaDung()
        {
            InitializeComponent();
            this.Height = Screen.PrimaryScreen.WorkingArea.Height; //ConfigForm.height;
            this.Width = Screen.PrimaryScreen.WorkingArea.Width;//configForm.width
        }

        private void binCombo(ComboBox cb, DataTable dt, string name, string value, string option)
        {
            List<trangthai> list = new List<trangthai>();
            trangthai ls = null;
            ls = new trangthai();
            ls.name = option;
            ls.value = "0";
            list.Add(ls);
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    ls = new trangthai();
                    ls.name = dt.Rows[i][name].ToString();
                    ls.value = dt.Rows[i][value].ToString();
                    list.Add(ls);
                }
            }
            cb.DataSource = list;
            cb.DisplayMember = "name";
            cb.ValueMember = "value";
        }

        private void reportTuGiaDung_Load(object sender, EventArgs e)
        {
            this.reportViewerTuGiaDung.RefreshReport();
            clDHTong dht = new clDHTong();
            DataTable dtdht = dht.getdata(0);
            binCombo(cbbDHT,dtdht,"tenDHTong","id"," ");

            clPX px = new clPX();
            DataTable dtpx = px.getdata(0, 0);
            binCombo(cbbPhuong,dtpx,"ten","id"," ");

            DataTable dt = new DataTable();

            binCombo(cbbPho, dt, "ten", "id", " ");

            //clPho pho = new clPho();
            //DataTable dtpho = pho.getdata(0, 0);
            //binCombo(cbbPho,dtpho,"ten","id","<Chọn Đường / Phố>");
        }

        private void btquit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string ngaylap = dateview.Value.ToString("MM/dd/yyyy");
            Int16 idDHT = Int16.Parse(cbbDHT.SelectedValue.ToString());
            Int16 idPhuong = Int16.Parse(cbbPhuong.SelectedValue.ToString());
            Int16 idpho = Int16.Parse(cbbPho.SelectedValue.ToString());

            clReport CQcp = new clReport();
            DataTable dt = CQcp.reportTuGiaDung(ngaylap,idDHT,idPhuong,idpho);
            ReportDataSource rpcq = new ReportDataSource();
            rpcq.Name = "DatasetTuGiaDung";
            rpcq.Value = dt;

            this.reportViewerTuGiaDung.Reset();
            this.reportViewerTuGiaDung.LocalReport.ReportEmbeddedResource = "QLKH.View.report.BanKeBienLaiTuGia.rdlc";
            this.reportViewerTuGiaDung.LocalReport.DataSources.Clear();
            this.reportViewerTuGiaDung.LocalReport.DataSources.Add(rpcq);

            string tenDHT = cbbDHT.Text;
            string tenPhuong = cbbPhuong.Text;
            string tenpho = cbbPho.Text;

            IList<ReportParameter> param = new List<ReportParameter>();
            param.Add(new ReportParameter("Ngaylap", ngaylap));
            param.Add(new ReportParameter("TenDHT", tenDHT));
            param.Add(new ReportParameter("TenPhuong", tenPhuong));
            param.Add(new ReportParameter("TenPho", tenpho));

            reportViewerTuGiaDung.LocalReport.SetParameters(param);

            this.reportViewerTuGiaDung.RefreshReport();
            //this.reportViewerTuGiaDung.ZoomPercent = 100;
            this.reportViewerTuGiaDung.SetDisplayMode(DisplayMode.PrintLayout);
            this.reportViewerTuGiaDung.ZoomMode = ZoomMode.Percent;
            this.reportViewerTuGiaDung.ZoomPercent = 100;
        }

        private void cbbPhuong_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                Int16 pxid = Int16.Parse((cbbPhuong.SelectedValue == null) ? "0" : cbbPhuong.SelectedValue.ToString().Trim());
                if (pxid > 0)
                {
                    clPho p = new clPho();
                    DataTable dtp = p.getdata(1, pxid);
                    binCombo(cbbPho, dtp, "ten", "id", " ");
                }
            }
            catch { } 
        }
    }
}
